﻿using System.Windows;
using QDP.Platform.Services;

public static class MessageExtensions
{
    #region IMessageService
    private static IMessageService service = null;
    private static IMessageService GetMessage<T>(this T me) where T : class
    {
        if (service == null)
        {
            service = ServiceLoader.Load<IMessageService>();
        }
        return service;
    }
    /// <summary>显示包含指定文本、标题栏标题和响应按钮的消息框。</summary>
    /// <param name="Message">消息的参数结构</param>
    /// <returns>一个值，用于指示用户对消息的响应。</returns>
    public static MessageBoxResult ShowMessage<T>(this T me, MessageContract Message) where T : class
    {
        if (service == null) GetMessage(me);
        //return MessageBox.Show(Message.Message, Message.Title, Message.Button);
        // 服务调用时，优先导入一次服务，无论导入结构如何，均进行后续操作.
        if (service == null)
        {
            return MessageBox.Show(Message.Message, Message.Title, Message.Button);
        }
        else
        {
            return service.Show(Message);
        }
    }
    public static void ShowMessage<T>(this T me, string title, string content) where T : class
    {
        if (service == null) GetMessage(me);
        //return MessageBox.Show(Message.Message, Message.Title, Message.Button);
        // 服务调用时，优先导入一次服务，无论导入结构如何，均进行后续操作.
        if (service == null)
        {
            MessageBox.Show(content, title, MessageBoxButton.OK);
        }
        else
        {
            service.Show(new MessageContract()
            {
                Message = content,
                Title = title,
                Button = MessageBoxButton.OK
            });
        }
    }
    /// <summary>显示包含指定文本和"确定"按钮的消息框。</summary>
    /// <param name="Content">要显示的消息</param>
    /// <returns>一个值，用于指示用户对消息的响应。</returns>
    public static void ShowMessage<T>(this T me,string Content)where T:class
    {
        if (service == null) GetMessage(me);
        if (service == null)
        {
            MessageBox.Show(Content);
        }
        else
        {
            service.Show(Content);
        }
    }
    #endregion //#region IMessageService
}